package com.ruoyi.monitor.mapper;


import cn.hutool.db.sql.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.monitor.Vo.PollutantMonthVo;
import com.ruoyi.monitor.domain.PollutantAvg;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 均值Mapper接口
 * 
 * @author 徐泽炫
 * @date 2023-01-12
 */

public interface PollutantAvgMapper extends BaseMapper<PollutantAvg>
{
    //不同年份中不同空气质量的天数
    @Select("SELECT a.`date`,count(aqi) as total\n" +
            "FROM\n" +
            "(\n" +
            "SELECT DATE_FORMAT(ct,'%Y') as 'date',aqi,type,area\n" +
            "FROM avg_pollutant\n" +
            "WHERE ${ew.sqlSegment}\n" +
            ")\n" +
            "as a\n" +
            "${ew.customSqlSegment}\n" +
            "GROUP BY a.`date`")
    List<PollutantMonthVo> selectDaysOfQuantityYear(@Param(Constants.WRAPPER)QueryWrapper wrapper);
    //
    @Select("SELECT a.`date`,count(aqi) as total\n" +
            "FROM\n" +
            "(\n" +
            "SELECT DATE_FORMAT(ct,'%Y-%m') as 'date',aqi,type,area\n" +
            "FROM avg_pollutant\n" +
            "WHERE ${ew.sqlSegment}\n" +
            ")\n" +
            "as a\n" +
            "${ew.customSqlSegment}\n" +
            "GROUP BY a.`date`")
    List<PollutantMonthVo> selectDaysOfQuantity(@Param(Constants.WRAPPER)QueryWrapper wrapper);
    /**
     * 查询均值查询
     *
     * @param id 均值查询主键
     * @return 均值查询
     */
    public PollutantAvg selectPollutantAvgById(Long id);

    /**
     * 查询均值查询列表
     *
     * @param pollutantAvg 均值查询
     * @return 均值查询集合
     */
    public List<PollutantAvg> selectPollutantAvgList(PollutantAvg pollutantAvg);

    /**
     * 新增均值查询
     *
     * @param pollutantAvg 均值查询
     * @return 结果
     */
    public int insertPollutantAvg(PollutantAvg pollutantAvg);

    /**
     * 修改均值查询
     *
     * @param pollutantAvg 均值查询
     * @return 结果
     */
    public int updatePollutantAvg(PollutantAvg pollutantAvg);

    /**
     * 删除均值查询
     *
     * @param id 均值查询主键
     * @return 结果
     */
    public int deletePollutantAvgById(Long id);

    /**
     * 批量删除均值查询
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deletePollutantAvgByIds(Long[] ids);
}
